package com.xhh.nphm.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhh.nphm.system.domain.MakeTagUser;
import com.xhh.nphm.system.domain.TtelGetDealEty;
import org.apache.ibatis.annotations.*;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;
import java.util.Map;


@Mapper
public interface MakeTagUserDao extends BaseMapper<MakeTagUser> {

    /**
     * 查询对应电话工单的标签
     * @param telWfId 电话工单 id
     * @return
     */
    @Select(" select tag_PkId as tagNo,tag_name as tagName " +
            " from  tm_makeTagT_user " +
            " where tel_id = #{telWfId} and is_del = 0 and dept_id = #{deptId} and user_id = #{userId}")
    List<Map<String, Object>> selectTelExistTag(@Param("telWfId") String telWfId, @Param("deptId") String deptId, @Param("userId") String userId);


    /**
     * 查询对应信件工单的标签
     * @param mailWfId 信件工单 id
     * @return
     */
    @Select(" select tag_PkId as tagNo,tag_name as tagName " +
            " from tm_makeTagM_user " +
            " where mail_id = #{mailWfId} and is_del = 0 and dept_id = #{deptId} and user_id = #{userId}")
    List<Map<String, Object>> selectMailExistTag(@Param("mailWfId") String mailWfId, @Param("deptId") String deptId, @Param("userId") String userId);

    /**
     *
     * @param makeTagUser 操作者实体
     * @return
     */
    @Insert(" insert into " +
            " tm_makeTagT_user(tag_PkId,tag_name,user_id,user_name,dept_id,dept_name,create_time,tel_id)" +
            " values(#{tagPkid},#{tagName},#{userId},#{userName},#{deptId},#{deptName},#{createTime},#{recordId}) ")
    int saveTelMakeTagByUser(MakeTagUser makeTagUser);

    /**
     * 保存信件打标签操作信息
     * @param makeTagUser 操作者实体
     * @return
     */
    @Insert(" insert into " +
            " tm_makeTagM_user(tag_PkId,tag_name,user_id,user_name,dept_id,dept_name,create_time,mail_id)" +
            " values(#{tagPkid},#{tagName},#{userId},#{userName},#{deptId},#{deptName},#{createTime},#{recordId}) ")
    int saveMailMakeTagByUser(MakeTagUser makeTagUser);

    /**
     * 更新电话工单某个标签
     * @param recordId 电话id
     * @param tagPkid 标签id
     * @param deptId 操作部门id
     * @return
     */
    @Update("update tm_makeTagT_user set is_del = 0 where tel_id = #{telId} and tag_PkId = #{tagId} and dept_id = #{deptId}")
    int updateByTagNoTel(@Param("telId") String recordId, @Param("tagId") Long tagPkid, @Param("deptId") String deptId);

    /**
     * 更新信件工单某个标签
     * @param recordId 信件id
     * @param tagPkid 标签id
     * @param deptId 操作部门id
     * @return
     */
    @Update("update tm_makeTagM_user set is_del = 0 where mail_id = #{mailId} and tag_PkId = #{tagId} and dept_id = #{deptId}")
    int updateByTagNoMail(@Param("mailId") String recordId, @Param("tagId") Long tagPkid, @Param("deptId") String deptId);

    /**
     * 删除电话工单的某个标签
     * @param recordId 电话id
     * @param tagPkid 标签id
     * @param deptId 操作部门id
     * @return
     */
    @Update("update tm_makeTagT_user set is_del = 1 where tel_id = #{telId} and tag_PkId = #{tagId} and dept_id = #{deptId}")
    int deleteByTagNoTel(@Param("telId") String recordId, @Param("tagId") Long tagPkid, @Param("deptId") String deptId);

    /**
     * 删除信件工单的某个标签
     * @param recordId 信件id
     * @param tagPkid 标签id
     * @param deptId 操作部门id
     * @return
     */
    @Update("update tm_makeTagM_user set is_del = 1 where mail_id = #{mailId} and tag_PkId = #{tagId} and dept_id = #{deptId}")
    int deleteByTagNoMail(@Param("mailId") String recordId, @Param("tagId") Long tagPkid, @Param("deptId") String deptId);
}
